<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>MyRSA</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="row">
    <div class="col-md-4"></div>
    <div class="col-md-4"><h1 align="center">This is our RSA</h1></div>
    <div class="col-md-4"></div>
</div>
<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <div class="row">
            <div class="col-md-4">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">这里输入明文</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">明文</span>
                                    <input type="text" class="form-control" id="ming" placeholder="请输入明文">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">公钥</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">N</span>
                                    <input type="text" class="form-control" id="pubKey-n" placeholder="RSA生成整数N">
                                </div>
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">E</span>
                                    <input type="text" class="form-control" id="pubKey-e" placeholder="RSA生成整数E">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="row">
                    <div class="col-md-6">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">这里输入素数P</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">P</span>
                                    <input type="text" class="form-control" id="p" placeholder="请输入一个素数">
                                </div>
                            </div>
                            <div class="panel-body" align="center">
                                <button type="button" class="btn btn-success" id="p-btn">生成相近素数</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">这里输入Q</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">Q</span>
                                    <input type="text" class="form-control" id="q" placeholder="请输入一个素数">
                                </div>
                            </div>
                            <div class="panel-body" align="center">
                                <button type="button" class="btn btn-success" id="q-btn">生成相近素数</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12">
                        <div class="panel panel-default">
                            <div class="panel-body" align="center">
                                <button type="button" class="btn btn-warning" id="getRSA">生成RSA</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12">
                        <div class="panel panel-default">
                            <div class="panel-body" align="center">
                                <button type="button" class="btn btn-info" id="encode">加密》》》》》》》》》》</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12">
                        <div class="panel panel-default">
                            <div class="panel-body" align="center">
                                <button type="button" class="btn btn-info" id="decode">解密《《《《《《《《《《</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">这里显示密文</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">密文</span>
                                    <input type="text" class="form-control" id="mi" placeholder="密文">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">私钥</h3>
                            </div>
                            <div class="panel-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">N</span>
                                    <input type="text" class="form-control" id="priKey-n" placeholder="RSA生成整数N">
                                </div>
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">D</span>
                                    <input type="text" class="form-control" id="priKey-d" placeholder="RSA生成整数D">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">

        </div>
    </div>
    <div class="col-md-1"></div>
</div>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script>
    $(document).ready(function(){

        $("#p-btn").click(function(){
            $.ajax({
                type: "GET",
                url: "/rsa/getPrime",
                data: {
                    prime:$("#p").val(),
                },
                success: function(data){
                    console.log("p-success");
                    console.log(data);
                    $("#p").val(data);
                }
            });
        });

        $("#q-btn").click(function(){
            $.ajax({
                type: "GET",
                url: "/rsa/getPrime",
                data: {
                    prime:$("#q").val(),
                },
                success: function(data){
                    console.log("q-success");
                    console.log(data);
                    $("#q").val(data);
                }
            });
        });

        $("#encode").click(function(){
            $.ajax({
                type: "GET",
                url: "/rsa/encode",
                data: {
                    ming:$("#ming").val(),
                    p:$("#p").val(),
                    q:$("#q").val(),
                    n:$("#priKey-n").val(),
                    e:$("#pubKey-e").val(),
                    d:$("#priKey-d").val(),
                },
                success: function(data){
                    console.log("encode-success");
                    console.log(data);
                    $("#mi").val(data);
                }
            });
        });

        $("#decode").click(function(){
            $.ajax({
                type: "GET",
                url: "/rsa/decode",
                data: {
                    mi:$("#mi").val(),
                    p:$("#p").val(),
                    q:$("#q").val(),
                    n:$("#priKey-n").val(),
                    e:$("#pubKey-e").val(),
                    d:$("#priKey-d").val(),
                },
                success: function(data){
                    console.log("decode-success");
                    console.log(data);
                    $("#ming").val(data);
                }
            });
        });

        $("#getRSA").click(function(){
            $.ajax({
                type: "GET",
                url: "/rsa/getRSANum",
                data: {
                    p:$("#p").val(),
                    q:$("#q").val(),
                },
                success: function(data){
                    console.log("getRSA-success");
                    console.log(data);
                    $("#priKey-d").val(data.d);
                    $("#priKey-n").val(data.n);
                    $("#pubKey-e").val(data.e);
                    $("#pubKey-n").val(data.n);
                }
            });
        });
    });
</script>
</body>
</html>